package com.example.pathprotectsystem.mapper;

import com.example.pathprotectsystem.pojo.ResultModel;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface RecordMapper {
    @Select("select count(*) from daycheck where taskId = #{id}")
    int findTaskIdFromf1(int id);
    @Select("select count(*) from facilitydamage where taskId = #{id}")
    int findTaskIdFromf2(int id);
    @Select("select count(*) from pavementflat where taskId = #{id}")
    int findTaskIdFromf3(int id);
    @Select("select count(*) from pavementdamage where taskId = #{id}")
    int findTaskIdFromf4(int id);
    @Select("select * from daycheck " +
            "join task on daycheck.taskId=task.id " +
            "join path on task.pathId=path.id " +
            "join user on task.userId=user.id " +
            "where daycheck.finishTime like concat('%',concat(#{str},'%')) or " +
            "user.userName like concat('%',concat(#{str},'%')) or " +
            "task.pathId like concat('%',concat(#{str},'%')) or " +
            "path.pathName like concat('%',concat(#{str},'%')) or " +
            "daycheck.damageType like concat('%',concat(#{str},'%')) or " +
            "daycheck.damageDescribe like concat('%',concat(#{str},'%')) or " +
            "daycheck.comment like concat('%',concat(#{str},'%')) " +
            "order by daycheck.finishTime desc")
    List<ResultModel> f1list(String str);
    @Delete("delete from daycheck where id=#{id}")
    void deletef1(int id);
    @Delete("delete from facilitydamage where id=#{id}")
    void deletef2(int id);
    @Select("select * from facilitydamage " +
            "join task on facilitydamage.taskId=task.id " +
            "join path on task.pathId=path.id " +
            "join user on task.userId=user.id " +
            "where facilitydamage.finishTime like concat('%',concat(#{str},'%')) or " +
            "user.userName like concat('%',concat(#{str},'%')) or " +
            "path.pathName like concat('%',concat(#{str},'%')) or " +
            "facilitydamage.facilityName like concat('%',concat(#{str},'%')) or " +
            "facilitydamage.damagePart like concat('%',concat(#{str},'%')) or " +
            "facilitydamage.damageReason like concat('%',concat(#{str},'%')) or " +
            "facilitydamage.suggest like concat('%',concat(#{str},'%')) " +
            "order by facilitydamage.finishTime desc")
    List<ResultModel> f2list(String str);
    @Delete("delete from pavementflat where id=#{id}")
    void deletef3(int id);
    @Select("select * from pavementflat " +
            "join task on pavementflat.taskId=task.id " +
            "join path on task.pathId=path.id " +
            "join user on task.userId=user.id " +
            "where pavementflat.finishTime like concat('%',concat(#{str},'%')) or " +
            "user.userName like concat('%',concat(#{str},'%')) or " +
            "path.pathName like concat('%',concat(#{str},'%')) or " +
            "task.pathId like concat('%',concat(#{str},'%')) or " +
            "pavementflat.iri like concat('%',concat(#{str},'%')) or " +
            "pavementflat.comment like concat('%',concat(#{str},'%')) " +
            "order by pavementflat.finishTime desc")
    List<ResultModel> f3list(String str);
    @Delete("delete from pavementdamage where id=#{id}")
    void deletef4(int id);
    @Select("select * from pavementdamage " +
            "join task on pavementdamage.taskId=task.id " +
            "join path on task.pathId=path.id " +
            "join user on task.userId=user.id " +
            "where pavementdamage.finishTime like concat('%',concat(#{str},'%')) or " +
            "user.userName like concat('%',concat(#{str},'%')) or " +
            "path.pathName like concat('%',concat(#{str},'%')) or " +
            "task.pathId like concat('%',concat(#{str},'%')) or " +
            "pavementdamage.allLongth like concat('%',concat(#{str},'%')) or " +
            "pavementdamage.allWidth like concat('%',concat(#{str},'%')) or " +
            "pavementdamage.damageType like concat('%',concat(#{str},'%')) or " +
            "pavementdamage.damageLongth like concat('%',concat(#{str},'%')) or " +
            "pavementdamage.damageWidth like concat('%',concat(#{str},'%')) or " +
            "pavementdamage.damageHighth like concat('%',concat(#{str},'%')) or " +
            "pavementdamage.damageDescribe like concat('%',concat(#{str},'%')) or " +
            "pavementdamage.damageArea like concat('%',concat(#{str},'%')) or " +
            "pavementdamage.comment like concat('%',concat(#{str},'%')) " +
            "order by pavementdamage.finishTime desc")
    List<ResultModel> f4list(String str);
    @Select("select user.userName,path.pathName,path.startAddress,path.pavementType,path.endAddress,group_concat(finishTime) as stringstr from pavementdamage " +
            "join task on pavementdamage.taskId=task.id " +
            "join path on task.pathId=path.id " +
            "join user on task.userId=user.id " +
            "where pavementdamage.finishTime like concat('%',concat(#{str},'%')) or " +
            "user.userName like concat('%',concat(#{str},'%')) or " +
            "path.pathName like concat('%',concat(#{str},'%')) or " +
            "path.startAddress like concat('%',concat(#{str},'%')) or " +
            "path.pavementType like concat('%',concat(#{str},'%')) or " +
            "path.endAddress like concat('%',concat(#{str},'%')) " +
            "group by pavementdamage.taskId,left(pavementdamage.finishTime,10)")
    List<ResultModel> f5list(String str);

    @Select("select liqingdamagetype.damageType,pavementdamage.damageArea," +
            "pavementdamage.damageArea/pavementdamage.allLongth/pavementdamage.allWidth as damageP," +
            "pavementdamage.comment,left(finishTime,10) as finishTime," +
            "user.userName,path.pathName from liqingdamagetype " +
            "left join pavementdamage on pavementdamage.damageType = liqingdamagetype.damageType " +
            "left join task on pavementdamage.taskId=task.id " +
            "left join path on task.pathId=path.id " +
            "left join user on task.userId=user.id")
    List<ResultModel> pavementdamagesheetlist();
    @Select("select shuinidamagetype.damageType,pavementdamage.damageArea," +
            "pavementdamage.damageArea/pavementdamage.allLongth/pavementdamage.allWidth as damageP," +
            "pavementdamage.comment,left(finishTime,10) as finishTime," +
            "user.userName,path.pathName from shuinidamagetype " +
            "left join pavementdamage on pavementdamage.damageType = shuinidamagetype.damageType " +
            "left join task on pavementdamage.taskId=task.id " +
            "left join path on task.pathId=path.id " +
            "left join user on task.userId=user.id")
    List<ResultModel> shuinipavementdamagesheetlist();
}
